# 继承

# 继承的概念
# 单继承
print('------------继承的概念--------------------')


class A(object):
    def __init__(self):
        pass

    def print_info(self):
        print('不行')
        pass

    pass


class B(A):
    pass


result = B()
result.print_info()
print('------------单继承--------------------')


# 1. 师⽗类
class Master(object):
    def __init__(self):
        self.kongfu = '[古法煎饼果⼦配⽅]'

    def make_cake(self):
        print(f'运⽤{self.kongfu}制作煎饼果⼦')


# 徒弟
class Prentice(Master):
    pass


# 创建徒弟
prentice = Prentice()
# 方法
prentice.make_cake()
# 属性
print(prentice.kongfu)

print()

print('------------多继承 当一个类有多个父类,默认使用第一个父类的同名方法和属性--------------------')


# 创建学校类
class School(object):
    def __init__(self):
        self.kongfu = '[⿊⻢煎饼果⼦配⽅]'

    def make_cake(self):
        print(f'运⽤{self.kongfu}制作煎饼果⼦')


print()


class Prentice1(Master, School):
    pass


# # daqiu=Prentice1()
# print(daqiu.kongfu)
# daqiu.make_cake()
class Prentice2(School, Master):
    pass


daqiu = Prentice2()
print(daqiu.kongfu)
daqiu.make_cake()

print('------------⼦类重写⽗类的同名属性和⽅法--------------------')


class Prentice3(School, Master):
    def __init__(self):
        self.kongfu = '[自创的配方]'
        pass

    def make_cake(self):
        print(f'用{self.kongfu}来做事情')
        pass

    pass


prentice3 = Prentice3()
prentice3.make_cake()
print(prentice3.kongfu)

print('------------⼦类调⽤⽗类的同名属性和⽅法--------------------')


class Prentice4(School, Master):
    def __init__(self):
        self.kongfu = '[自创的配方]'
        pass

    def make_cake(self):
        self.__init__()
        print(f'用{self.kongfu}来做事情')

        pass

    # 调⽤⽗类⽅法，但是为保证调⽤到的也是⽗类的属性，必须在调⽤⽅法前调⽤⽗类的初始化
    def make_master_cake(self):
        Master.__init__(self)
        Master.make_cake(self)
        pass

    def make_school_cake(self):
        School.__init__(self)
        School.make_cake(self)
        pass

    pass


prentice4 = Prentice4()
prentice4.make_cake()
prentice4.make_master_cake()
prentice4.make_school_cake()
print(prentice4.kongfu)

print('------------多层继承--------------------')


class Tusun(Prentice4):
    pass


tusun = Tusun()
tusun.make_cake()
tusun.make_school_cake()
tusun.make_master_cake()
print(tusun.kongfu)
print()
print('------------super() 调用父类方法--------------------')


# 1. 师⽗类
class Master1(object):
    def __init__(self):
        self.kongfu = '[古法煎饼果⼦配⽅]'

    def make_cake(self):
        print(f'运⽤{self.kongfu}制作煎饼果⼦')


class School1(Master1):
    def __init__(self):
        self.kongfu = '[黑马煎饼果子配方]'
        pass

    pass


school1 = School1()
print(school1.kongfu)
school1.make_cake()

print('------------继承--------------------')

class Prentice5(School1, Master1):
    def __init__(self):
        self.kongfu = '[自创的方法]'
        pass

    def make_cake(self):
        print(f'使用{self.kongfu}制作煎饼果子')
        pass

    def make_old_cake(self) :
        print(f'使用{self.kongfu}制作煎饼果子')
        # ⽅法⼀：代码冗余；⽗类类名如果变化，这⾥代码需要频繁修改
        # Master1.__init__(self)
        # Master1.make_cake(self)
        # 方法2.1 平时不这么调用
        # super(School1, self).__init__()
        # super(School1, self).make_cake()

        # 方法2.2 super().函数()
        super().__init__()
        super().make_cake()
        pass

    pass
prentice5=Prentice5()
prentice5.make_old_cake()
print(prentice5.kongfu)

